package  com.pcbly.web.business.publicinfo;

/**
* @author carl.song
* Copyright (c) 2010 Lightsoft, International.
* All rights reserved.
*
*/

import java.util.HashMap;
import java.util.List;

import com.pcbly.web.persistence.publicinfo.MessageDao;
import com.pcbly.web.persistence.table.ColumnDao;
import com.pcbly.web.bean.publicinfo.MessageBean;
import com.pcbly.web.bean.table.ColumnBean;
import com.pcbly.web.business.BaseServiceImp;
import com.pcbly.web.components.hibernate.support.Page;
import com.pcbly.web.components.form.AbstractAnalyseCommonDataExt;
import com.pcbly.web.components.form.AnalyseCommonDataExtCreate;
import com.pcbly.web.components.form.AnalyseCommonDataExtEdit;
import com.pcbly.web.components.form.AnalyseCommonDataExtView;

 
public class MessageServiceImp extends BaseServiceImp<MessageBean> implements MessageService {
	 public MessageServiceImp() {
		super();
		// TODO Auto-generated constructor stub
	}
	private MessageDao messageDao;
	
	private ColumnDao columnDao;

	public void setColumnDao(ColumnDao columnDao) {
		this.columnDao = columnDao;
	}
	
	public void setMessageDao(MessageDao messageDao) {
		this.messageDao = messageDao;
	}
	
	@Override
	public MessageBean getMessageBeanById(String id) throws Exception {
		// TODO Auto-generated method stub
		return messageDao.get(MessageBean.class,id);
	}
	
	@Override
	public void removeMessageBeanById(String id) throws Exception{
		messageDao.removeMessageBeanById(id);
	}
	
	@Override
	public void removeMessageBeanByIds(String ids) throws Exception{
		messageDao.removeMessageBeanByIds(ids);
	}
	
	
	@Override
	public MessageBean saveMessageBean(MessageBean publicinfo) throws Exception{
		return messageDao.saveMessageBean(publicinfo);
	}
	
	@Override
	public MessageBean updateMessageBean(MessageBean publicinfo) throws Exception{
		messageDao.saveObject( publicinfo);
		return publicinfo;
	}
	public Page<MessageBean>  findMessageBeanByCond(MessageBean bean,
			Page<MessageBean> page, String orderByName, boolean asc)
			throws Exception{
		return messageDao.findMessageBeanByCond(
				bean, page, orderByName, asc);
	}
	
	@Override
	public String findMessageBeanExtCreate(String tableName) throws Exception {
		// TODO Auto-generated method stub
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtCreate();
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public String findMessageBeanExtEdit(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		List<HashMap<String, String>> dataList = messageDao
				.findCommnonDataBeanExt(tableName, id);
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtEdit();
		common.setDataList(dataList);
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public String findMessageBeanExtView(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		List<HashMap<String, String>> dataList = messageDao
				.findCommnonDataBeanExt(tableName, id);
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtView();
		common.setDataList(dataList);
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public void saveMessageBeanExt(String sql) throws Exception {
		// TODO Auto-generated method stub
		messageDao.saveCommnonDataBeanExt(sql);
	}

	@Override
	public boolean getHasMessageBeanExtData(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		return messageDao.getHasCommnonDataBeanExt(tableName, id);
	}
}
